//
//  WHViewGetCell.m
//  SquirrelCourier
//
//  Created by 邓伟浩 on 2019/1/3.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHViewGetCell.h"

@interface WHViewGetCell ()

@property (nonatomic, strong) UILabel *shopNameTitleLabel;
@property (nonatomic, strong) UILabel *inAndMoneyLabel;
@property (nonatomic, strong) UILabel *tipsLabel;
@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation WHViewGetCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpViewGetUI];
    }
    return self;
}

- (void)setUpViewGetUI {
    [self.contentView addSubview:({
        _shopNameTitleLabel = [[UILabel alloc] init];
        _shopNameTitleLabel.textColor = CFontTitleBlackColor;
        _shopNameTitleLabel.font = SYSTEMFONT(kRealwidth(16));
        
        _shopNameTitleLabel;
    })];
    [_shopNameTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(kRealwidth(30));
        make.top.mas_equalTo(self.contentView.mas_top).offset(kRealwidth(13));
        make.height.mas_equalTo(kRealwidth(16));
        
    }];
    
    [self.contentView addSubview:({
        _inAndMoneyLabel = [[UILabel alloc] init];
        
        _inAndMoneyLabel;
    })];
    [_inAndMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-kRealwidth(30));
        make.top.mas_equalTo(_shopNameTitleLabel.mas_top);
        make.height.mas_equalTo(kRealwidth(16));
    }];
    
    [self.contentView addSubview:({
        _tipsLabel = [[UILabel alloc] init];
        _tipsLabel.textColor = CFontContentLightGrayColor;
        _tipsLabel.font = SYSTEMFONT(kRealwidth(15));
        
        _tipsLabel;
    })];
    [_tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(kRealwidth(30));
        make.top.mas_equalTo(_shopNameTitleLabel.mas_bottom).offset(kRealwidth(13));
        make.height.mas_equalTo(kRealwidth(15));
        
    }];
    
    [self.contentView addSubview:({
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.textColor = CFontContentLightGrayColor;
        _dateLabel.font = SYSTEMFONT(kRealwidth(15));
        _dateLabel.textAlignment = NSTextAlignmentRight;
        
        _dateLabel;
    })];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-kRealwidth(30));
        make.top.mas_equalTo(_shopNameTitleLabel.mas_bottom).offset(kRealwidth(13));
        make.height.mas_equalTo(kRealwidth(15));
    }];
}

- (NSAttributedString *)getAttributrStrWithCountStr:(NSString *)countStr moneyStr:(NSString *)moneyStr {
    
    NSMutableAttributedString *resultAttStr = [[NSMutableAttributedString alloc] initWithString:@"入库件  " attributes:@{NSForegroundColorAttributeName:CFontContentGrayColor, NSFontAttributeName:SYSTEMFONT(kRealwidth(15))}];
    NSAttributedString *countAttStr = [[NSAttributedString alloc] initWithString:countStr attributes:@{NSForegroundColorAttributeName:CMDarkOrangeColor, NSFontAttributeName:SYSTEMFONT(kRealwidth(18))}];
    [resultAttStr insertAttributedString:countAttStr atIndex:2];
    
    NSMutableAttributedString *moneyAttStr = [[NSMutableAttributedString alloc] initWithString:moneyStr attributes:@{NSForegroundColorAttributeName:CMDarkOrangeColor, NSFontAttributeName:SYSTEMFONT(kRealwidth(18))}];
    NSAttributedString *moneyTipsAttStr = [[NSAttributedString alloc] initWithString:@"元" attributes:@{NSForegroundColorAttributeName:CFontContentGrayColor, NSFontAttributeName:SYSTEMFONT(kRealwidth(15))}];
    [moneyAttStr appendAttributedString:moneyTipsAttStr];
    
    [resultAttStr appendAttributedString:moneyAttStr];
    
    return resultAttStr;
}

- (void)setStationModel:(WHStationModel *)stationModel {
    _stationModel = stationModel;
    _shopNameTitleLabel.text = stationModel.stationName;
    _inAndMoneyLabel.attributedText = [self getAttributrStrWithCountStr:stationModel.intoStatus moneyStr:stationModel.handleBalance];
    _tipsLabel.text = NSStringFormat(@"包裹存管费：%@元/件", stationModel.saveMoney);
    _dateLabel.text = stationModel.updateTimeString;
}

- (void)prepareForReuse {
    [super prepareForReuse];
    _shopNameTitleLabel.text = @"";
    _inAndMoneyLabel.text = @"";
    _tipsLabel.text = @"";
    _dateLabel.text = @"";
}

@end
